﻿using AutoMapper.Internal.Mappers;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Dynamic.Core;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.Domain.Services;

namespace Himp.Platform
{
    public class CatgeDictManager : DomainService
    {
        private readonly IRepository<CatgeDict, Guid> _catgeDictRepository;

        public CatgeDictManager(IRepository<CatgeDict, Guid> catgeDictRepository)
        {
            _catgeDictRepository = catgeDictRepository;
        }

        public async Task<Tuple<List<CatgeDict>, int>> GetList(int pi, int ps, string? typeCode, string? fileter)
        {
            var iQuery = await _catgeDictRepository.WithDetailsAsync();
            iQuery = iQuery.Where(i => i.ParentId == null);
            iQuery = iQuery.WhereIf(!string.IsNullOrEmpty(typeCode), i => i.TypeCode == typeCode);
            iQuery = iQuery.WhereIf(!string.IsNullOrEmpty(fileter), i => i.CatgeCodg.Contains(fileter)|| i.CatgeName.Contains(fileter));
            var total = iQuery.Count();
            iQuery = iQuery.OrderBy(i => i.Srtno).Page(pi, ps);
            var menus = iQuery.ToList();

            return new Tuple<List<CatgeDict>, int>(menus, total);
        }

        public async Task<bool> DeleteRuleCheck(Guid id)
        {
            return true;
        }
    }
}
